<?php


namespace App\Models\CacheModel;


use App\Models\Api\BaseCache;
use think\Log;
use AstroTool\Cache\CacheManage;

class ZlBirthdayBoonGiveRecord extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.zl_birthday_boon_give_record';
    protected $cacheModel = 'user.coupon_birthday_boon_give_record';

    /**
     * 获取用户领取过生日的年份
     * @param int $uid
     * @return array
     * @throws \Exception
     */
    public function getBoonGiveYearList(int $uid): array
    {
        $data = CacheManage::getInstance()->setCacheConfig($this->cacheModel, $uid)->getDataAndSet(function () use ($uid)
        {
            try
            {
                $data = $this->where('uid', $uid)->column('year');
                $data = json_encode($data);
            }
            catch (\Exception $e)
            {
                Log::write('获取用户领取生日权益记录异常：' . $e->getMessage(), 'error');
                $data = '';
            }

            return $data;
        });

        $data = json_decode($data, true);

        return $data ?? [];
    }
}
